﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wwtfly.BBS.Framework.Common;
using Wwtfly.BBS.BackModels.Models.News;
using Wwtfly.LoggerUtility;
using Wwtfly.BBS.BackDAL.News;
using Wwtfly.BBS.Framework.Execption;
using System.Data;

namespace Wwtfly.BBS.BackBLL.News
{
    /// <summary>
    /// 新闻 bll
    /// </summary>
    public class NewsBLL
    {

        #region 属性
        //错误编码 (默认为不知原因的异常,使用者需要自己修改为相应的正确编码)
        private const string GET_INFO_ERROR_CODE = "9999";
        private const string GET_LIST_ERROR_CODE = "9999";
        private const string ADD_ERROR_CODE = "9999";
        private const string UPDATE_ERROR_CODE = "9999";
        private const string DELETE_ERROR_CODE = "9999";
        private const string NEWLIST_ERROR_CODE = "9999";
        #endregion
               /// <summary>
        ///  获取首页新闻列表
        /// </summary>
        /// <param name="sum">显示数据条数</param>
        /// <param name="TypeId">新闻类型ID</param>
        /// <returns></returns>
        public static DataTable NewsConetList(int sum, int TypeId)
        {
            try
            {
                DataTable dt = NewsDAL.NewsConetList(sum, TypeId);
                return dt;
            }
            catch (Exception ex)
            {
                
                LoggerManage.Error(new LogMessageParams()
                {
                    ModuleID = "NewsBLL",
                    FuncCode = " NewsConetList(int sum, int TypeId)",
                    Level = AppErrorLevel.EROR,
                    ErrCode = NEWLIST_ERROR_CODE,
                    Excep = ex,
                    logMessage = "根据新闻类型查询新闻.出错",
                    ProgramName = "Wwtilfy.BBS"
                });
                throw new WwtflyBusinessException("E_" + NEWLIST_ERROR_CODE, ex);
            }
        }
        /// <summary>
        /// 根据新闻类型查询10最新新闻
        /// </summary>
        /// <param name="TypeId"></param>
        /// <returns></returns>
        public static DataTable NewsList(int sum, int TypeId)
        {
            try
            {
                DataTable dt = NewsDAL.NewsList(sum, TypeId);
                return dt;
            }
            catch (Exception ex)
            {
                LoggerManage.Error(new LogMessageParams()
                {
                    ModuleID = "NewsBLL",
                    FuncCode = " NewsList(int sum, string TypeId)",
                    Level = AppErrorLevel.EROR,
                    ErrCode = NEWLIST_ERROR_CODE,
                    Excep = ex,
                    logMessage = "根据新闻类型查询新闻.出错",
                    ProgramName = "Wwtilfy.BBS"
                });
                throw new WwtflyBusinessException("E_" + NEWLIST_ERROR_CODE, ex);
            }
        }
        /// <summary>
        /// 分页 获取新闻 的相关信息
        /// </summary>
        /// <param name="pageParams">分页参数</param>
        /// <param name="searchModel">新闻搜索 实体类</param>
        /// <returns>分页后的结果</returns>
        public static PagedList<NewsShowsModel> GetNewsShowsPageList(PageParams pageParams, NewsShowsSearchModel searchModel)
        {
            try
            {
                return NewsDAL.GetNewsShowsPageList(pageParams, searchModel);
            }
            catch (Exception ex)
            {
                LoggerManage.Error(new LogMessageParams()
                {
                    ModuleID = "NewsBLL",
                    FuncCode = "PagedList<NewsShowsModel> GetNewsShowsPageList(PageParams pageParams, NewsShowsSearchModel searchModel)",
                    Level = AppErrorLevel.EROR,
                    ErrCode = "0x0",
                    Excep = ex,
                    logMessage = "分页 获取新闻 的相关信息.出错",
                    ProgramName = "Wwtilfy.BBS"
                });
                return PagedList<NewsShowsModel>.GetDefaultPageList<NewsShowsModel>();
            }
        }


        /// <summary>
        /// 根据Id获取指定的NewsShowsModel
        /// </summary>
        /// <param name="Id">/*-NewsShowsModel-*/主键</param>
        /// <returns>pmnewsShows实体</returns>
        public static NewsShowsModel GetInfo(Int32 Id)
        {
            try
            {
                return NewsDAL.GetInfo(Id);
            }
            catch (Exception ex)
            {
                LoggerManage.Error(new LogMessageParams()
              {
                  ModuleID = "NewsBLL",
                  FuncCode = "GetInfo(Int32 Id)",
                  Level = AppErrorLevel.EROR,
                  ErrCode = GET_INFO_ERROR_CODE,
                  Excep = ex,
                  logMessage = "根据Id获取指定的NewsShowsModel.出错",
                  ProgramName = "Wwtilfy.BBS"
              });
                throw new WwtflyBusinessException("E_" + GET_INFO_ERROR_CODE, ex);
            }
        }

        /// <summary>
        /// 添加新的model(新闻)
        /// </summary>
        /// <param name="model">model实体</param>
        /// <returns></returns>
        public static int Add(NewsShowsModel model)
        {
            //如果需要检查重复值，请再下面添加代码，并要抛出业务异常

            try
            {
                int val = NewsDAL.Add(model);
                return val;
            }
            catch (Exception ex)
            {
                LoggerManage.Error(new LogMessageParams()
                {
                    ModuleID = "NewsBLL",
                    FuncCode = "Add(NewsShowsModel model)",
                    Level = AppErrorLevel.EROR,
                    ErrCode = ADD_ERROR_CODE,
                    Excep = ex,
                    logMessage = "添加新的model(新闻).出错",
                    ProgramName = "Wwtilfy.BBS"
                });
                throw new WwtflyBusinessException("E_" + ADD_ERROR_CODE, ex);
            }
        }

        /// <summary>
        /// 修改model(新闻)
        /// </summary>
        /// <param name="pmnewsShows">model实体</param>
        /// <returns></returns>
        public static bool Update(NewsShowsModel model)
        {
            try
            {
                bool val = NewsDAL.Update(model);
                return val;
            }
            catch (Exception ex)
            {
                LoggerManage.Error(new LogMessageParams()
                {
                    ModuleID = "NewsBLL",
                    FuncCode = "Update(NewsShowsModel model)",
                    Level = AppErrorLevel.EROR,
                    ErrCode = UPDATE_ERROR_CODE,
                    Excep = ex,
                    logMessage = "修改model(新闻).出错",
                    ProgramName = "Wwtilfy.BBS"
                });
                throw new WwtflyBusinessException("E_" + UPDATE_ERROR_CODE, ex);
            }
        }

        /// <summary>
        /// 删除model(新闻)
        /// </summary>
        /// <param name="Id">model(新闻)主键</param>
        /// <returns></returns>
        public static bool Delete(Int32 Id)
        {
            try
            {
                bool val = NewsDAL.Delete(Id);

                return val;
            }
            catch (Exception ex)
            {
                LoggerManage.Error(new LogMessageParams()
                {
                    ModuleID = "NewsBLL",
                    FuncCode = " Delete(Int32 Id)",
                    Level = AppErrorLevel.EROR,
                    ErrCode = DELETE_ERROR_CODE,
                    Excep = ex,
                    logMessage = "删除model(新闻).出错",
                    ProgramName = "Wwtilfy.BBS"
                }); 
                throw new WwtflyBusinessException("E_" + DELETE_ERROR_CODE, ex);
            }
        }

    }
}
